//
//  ViewController.m
//  UIWebView浏览器
//
//  Created by 随 on 2017/4/10.
//  Copyright © 2017年 zzg. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
<UIWebViewDelegate>
{
    UIWebView * web;
    
    UIActivityIndicatorView * av;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    web = [[UIWebView alloc]initWithFrame:self.view.bounds];
    
    web.delegate = self;
    
    [self.view addSubview:web];
    
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.qq.com"]]];
    
    //将av推到视图最前
    //[self.view bringSubviewToFront:av];
    
}

//网页加载时：
-(void)webViewDidStartLoad:(UIWebView *)webView
{
    av = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    
    //旋转时显示，不转时隐藏
    av.hidesWhenStopped = YES;
    
    [av sizeToFit];
    
    av.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
    
    [av startAnimating];
    
    [self.view addSubview:av];
}

//网页加载成功后
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [av stopAnimating];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
